package com.ruoyi.web.controller.Sign;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.Sign.domain.Sign;
import com.ruoyi.Sign.service.ISignService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 签到 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-09-05
 */
@Controller
@RequestMapping("/Sign/sign")
public class SignController extends BaseController
{
    private String prefix = "Sign/sign";
	
	@Autowired
	private ISignService signService;
	
	@RequiresPermissions("Sign:sign:view")
	@GetMapping()
	public String sign()
	{
	    return prefix + "/sign";
	}
	
	/**
	 * 查询签到列表
	 */
	@RequiresPermissions("Sign:sign:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Sign sign)
	{
		startPage();
        List<Sign> list = signService.selectSignList(sign);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出签到列表
	 */
	@RequiresPermissions("Sign:sign:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Sign sign)
    {
    	List<Sign> list = signService.selectSignList(sign);
        ExcelUtil<Sign> util = new ExcelUtil<Sign>(Sign.class);
        return util.exportExcel(list, "sign");
    }
	
	/**
	 * 新增签到
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存签到
	 */
	@RequiresPermissions("Sign:sign:add")
	@Log(title = "签到", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Sign sign)
	{		
		return toAjax(signService.insertSign(sign));
	}

	/**
	 * 修改签到
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Sign sign = signService.selectSignById(id);
		mmap.put("sign", sign);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存签到
	 */
	@RequiresPermissions("Sign:sign:edit")
	@Log(title = "签到", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Sign sign)
	{		
		return toAjax(signService.updateSign(sign));
	}
	
	/**
	 * 删除签到
	 */
	@RequiresPermissions("Sign:sign:remove")
	@Log(title = "签到", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(signService.deleteSignByIds(ids));
	}
	
}
